From 6e1226c640fae22495a374fdc827ebdd03e711ee Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 15 May 2007 18:45:20 +0000 Subject: [PATCH] * API: JSON format now allows callback parameter --- includes/api/ApiFormatJson.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 99979d207d..8184c8c74b 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -49,14 +49,35 @@ class ApiFormatJson extends ApiFormatBase { } public function execute() { + $prefix = $suffix = ""; + + $params = $this->extractRequestParams(); + $callback = $params['callback']; + if(!is_null($callback)) { + $prefix = ereg_replace("[^_A-Za-z0-9]", "", $callback ) . "("; + $suffix = ")"; + } + if (!function_exists('json_encode') || $this->getIsHtml()) { $json = new Services_JSON(); - $this->printText($json->encode($this->getResultData(), $this->getIsHtml())); + $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix); } else { - $this->printText(json_encode($this->getResultData())); + $this->printText($prefix . json_encode($this->getResultData()) . $suffix); } } + protected function getAllowedParams() { + return array ( + 'callback' => null + ); + } + + protected function getParamDescription() { + return array ( + 'callback' => 'If specified, wraps the output into a given function call', + ); + } + protected function getDescription() { if ($this->mIsRaw) return 'Output data with the debuging elements in JSON format' . parent :: getDescription(); -- 2.20.1